<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;

/**
 * @property Carbon $expired_at
 * @method self active()
 */
class AuthCode extends Model
{
    public $dates = ['expired_at'];
    protected $fillable = ['area_code', 'phone', 'auth_code', 'expired_at'];
    public $timestamps = false;

    public function expire()
    {
        $this->expired_at = Carbon::now()->subSecond(1);
        $this->save();
    }

    public function scopeActive(Builder $query)
    {
        return $query->where('expired_at', '>', Carbon::now());
    }
}